package Homework;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*4.写两个线程，一个线程打印1~ 52，另一个线程打印A~Z，打印顺序是12A34B…5152Z*/
public class work06 {
    public static void main(String[] args) {
        Object lock = new Object();

        ExecutorService executor = Executors.newFixedThreadPool(2);

        executor.submit(() -> {
            synchronized (lock) {
                for (int i = 1; i <= 52; i++) {
                    if (i != 1 && i % 2 != 0) {
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        lock.notify();
                    }
                    System.out.print(i);
                }
            }
        });

        executor.submit(() -> {
            synchronized (lock) {
                for (char c = 'A'; c <= 'Z'; c++) {
                    System.out.print(c);
                    lock.notify();
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        executor.shutdown();
    }
}
